#pragma once

#include "Object.h"

class House : public Object
{
private:
	void setDoorColorMaterial()
	{
		GLfloat mat_ambient[] = {0.3f, 0.2f, 0.0f, 1.0f};
		GLfloat mat_diffuse[] = {0.3f, 0.2f, 0.0f, 1.0f};
		GLfloat mat_specular[] = {0.3f, 0.2f, 0.0f, 1.0f};
		GLfloat mat_shininess[] = {1.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
		glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	}

	void setWallColorMaterial()
	{
		GLfloat mat_ambient[] = {0.8f, 0.8f, 0.2f, 1.0f};
		GLfloat mat_diffuse[] = {0.8f, 0.8f, 0.2f, 1.0f};
		GLfloat mat_specular[] = {0.8f, 0.8f, 0.2f, 1.0f};
		GLfloat mat_shininess[] = {1.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
		glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	}

	void setWindowColorMaterial()
	{
		GLfloat mat_ambient[] = {0.0f, 0.3f, 1.0f, 1.0f};
		GLfloat mat_diffuse[] = {0.0f, 0.3f, 1.0f, 1.0f};
		GLfloat mat_specular[] = {0.2f, 0.2f, 0.2f, 1.0f};
		GLfloat mat_shininess[] = {10.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
		glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	}

	void setTrimColorMaterial()
	{
		GLfloat mat_ambient[] = {0.8f, 0.8f, 0.8f, 1.0f};
		GLfloat mat_diffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
		GLfloat mat_specular[] = {0.8f, 0.8f, 0.8f, 1.0f};
		GLfloat mat_shininess[] = {0.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
		glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	}

	void setRoofColorMaterial()
	{
		GLfloat mat_ambient[] = {0.25f, 0.1f, 0.0f, 1.0f};
		GLfloat mat_diffuse[] = {0.25f, 0.1f, 0.0f, 1.0f};
		GLfloat mat_specular[] = {0.25f, 0.1f, 0.0f, 1.0f};
		GLfloat mat_shininess[] = {1.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
		glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
		glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
	}

	void drawMain()
	{
		float roofPitch = 0.33;

		// The base box
		setWallColorMaterial();
		glBegin(GL_QUADS);
			// Left face
			glNormal3f(-1, 0, 0);
			glVertex3d(position.x - 0.5, position.y, position.z - 0.5);
			glVertex3d(position.x - 0.5, position.y, position.z + 0.5);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z + 0.5);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z - 0.5);

			// Front face
			glNormal3f(0, 0, 1);
			glVertex3d(position.x - 0.5, position.y, position.z + 0.5);
			glVertex3d(position.x + 0.5, position.y, position.z + 0.5);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z + 0.5);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z + 0.5);

			// Right face
			glNormal3f(1, 0, 0);
			glVertex3d(position.x + 0.5, position.y, position.z + 0.5);
			glVertex3d(position.x + 0.5, position.y, position.z - 0.5);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z - 0.5);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z + 0.5);

			// Back face
			glNormal3f(0, 0, -1);
			glVertex3d(position.x + 0.5, position.y, position.z - 0.5);
			glVertex3d(position.x - 0.5, position.y, position.z - 0.5);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z - 0.5);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z - 0.5);
		glEnd();
		glBegin(GL_TRIANGLES);
			// Left face
			glNormal3f(-1, 0, 0);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z - 0.5);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z + 0.5);
			glVertex3d(position.x - 0.5, position.y + 1, position.z);

			// Right face
			glNormal3f(1, 0, 0);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z - 0.5);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z + 0.5);
			glVertex3d(position.x + 0.5, position.y + 1, position.z);
		glEnd();

		// The roof
		setRoofColorMaterial();
		glBegin(GL_QUADS);
			// Back side roof
			glNormal3f(0, 0.66, -0.33);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z - 0.5);
			glVertex3d(position.x - 0.5, position.y + 1, position.z);
			glVertex3d(position.x + 0.5, position.y + 1, position.z);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z - 0.5);

			// Front side roof
			glNormal3f(0, 0.66, 0.33);
			glVertex3d(position.x - 0.5, position.y + 1 - roofPitch, position.z + 0.5);
			glVertex3d(position.x + 0.5, position.y + 1 - roofPitch, position.z + 0.5);
			glVertex3d(position.x + 0.5, position.y + 1, position.z);
			glVertex3d(position.x - 0.5, position.y + 1, position.z);
		glEnd();
	}

	void drawDoor()
	{
		setDoorColorMaterial();

		glPushMatrix();
		glTranslated(0, .25, .5);
		glScaled(0.25, 0.5, 0.01);
		glutSolidCube(1);
		glPopMatrix();

		// Draw the trim around the door
		setTrimColorMaterial();
		glPushMatrix();
		glTranslated(0, .5, .5);
		glScaled(0.26, 0.01, 0.015);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glTranslated(.125, .25, .5);
		glScaled(0.01, 0.51, 0.015);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glTranslated(-.125, .25, .5);
		glScaled(0.01, 0.51, 0.015);
		glutSolidCube(1);
		glPopMatrix();
	}

	void drawWindow()
	{
		setWindowColorMaterial();

		glPushMatrix();
		glScaled(0.25, 0.25, 0.01);
		glutSolidCube(1);
		glPopMatrix();

		// Draw the trim in and around the window
		setTrimColorMaterial();
		glPushMatrix();
		glScaled(0.26, 0.01, 0.015);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glScaled(0.01, 0.26, 0.015);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glTranslated(0, .13, 0);
		glScaled(0.26, 0.01, 0.015);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glTranslated(0, -.13, 0);
		glScaled(0.26, 0.01, 0.015);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glTranslated(.13, 0, 0);
		glScaled(0.01, 0.26, 0.015);
		glutSolidCube(1);
		glPopMatrix();

		glPushMatrix();
		glTranslated(-.13, 0, 0);
		glScaled(0.01, 0.26, 0.015);
		glutSolidCube(1);
		glPopMatrix();
	}

public:
	House(float x, float y, float z, float size, float angle)
	{
		setPosition(x, y, z);
		setSize(size);
		setRotation(angle);
	}

	void draw()
	{
		glPushMatrix();

		// Transformations
		glScaled(size,size,size);
		glTranslated(position.x, position.y, position.z);
		glRotatef(rotation, 0, 1, 0);

		drawMain();

		drawDoor();

		glPushMatrix();
		glTranslated(.33, .37, .5);
		drawWindow();
		glPopMatrix();

		glPushMatrix();
		glTranslated(-.33, .37, .5);
		drawWindow();
		glPopMatrix();

		glPushMatrix();
		glTranslated(.3, .37, -.5);
		drawWindow();
		glPopMatrix();

		glPushMatrix();
		glTranslated(-.3, .37, -.5);
		drawWindow();
		glPopMatrix();

		glPopMatrix();
	}

	void update(float delta) {}
};
